import { POP, NEW, SELL } from "./const";

import { debounce } from "common/utils";
import BackTop from "components/content/backTop/BackTop";

export const itemListenerMixin = {
    data() {
        return {
            itemImgListener: null,
            newRefresh: null

        }
    },
    mounted() {
        //1、图片加载完成的事件监听
        //传入函数 而不是传入返回值 不需要小括号
        this.newRefresh = debounce(this.$refs.scroll.refresh, 300);
        //闭包引入的都是同一个变量 不会重复引用
        this.itemImgListener = () => {
            this.newRefresh();
            // this.$refs.scroll.refresh();
        };
        //监听item中图片加载完成
        this.$bus.$on("itemImageLoad", this.itemImgListener);
    }
}
export const backTopMixin = {
    components: {
        BackTop
    },
    data() {
        return {
            isShowBackTop: false,

        }
    },
    methods: {
        backClick() {
            this.$refs.scroll.scrollTo(0, 0, 2000);
        },
    }
}

export const tabControlMixin = {
    data: function () {
        return {
            currentType: POP
        }
    },
    methods: {
        tabClick(index) {
            switch (index) {
                case 0:
                    this.currentType = POP
                    break
                case 1:
                    this.currentType = NEW
                    break
                case 2:
                    this.currentType = SELL
                    break
            }
            console.log(this.currentType);
        }
    }
}